package com.scqzy.shengchunqiang.sword2offer.day09;

/**
 * @Description: 剑指 Offer 47. 礼物的最大价值
 * @Author 盛春强
 * @Date 2021/8/16 10:49
 */
public class MaxValue {
    public int maxValue(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                // 从上或左dp较大值加上当前值
                dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]) + grid[i - 1][j - 1];
            }
        }
        return dp[m][n];
    }
}
